package servlet;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import model.Movie;
/**
 * Servlet implementation class MovieDetail
 */
@WebServlet("/MovieDetail")
public class MovieDetails extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public MovieDetails() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		Movie[] displayListMovies = null;
		try{
			services.ServiceProxy proxy = new services.ServiceProxy();
			proxy.setEndpoint("http://localhost:8080/videolibrary/services/Service");
			HttpSession session = request.getSession();
			//System.out.println(session.getAttribute("selectedMovieID")+"::::::::::::::::::::::::::::::::");
			displayListMovies = proxy.displayMovies(request.getParameter("char"));
			request.setAttribute("fetchedMovieListDetails",displayListMovies);
			RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/LibraryJSP/MovieDetails.jsp");
//			request.setAttribute("result", displayListMovies);
			dispatcher.forward(request, response);
			
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	public Movie[] getLatestMovieDetails(){

		Movie[] latestMovieDetailsArray = null;
		try{
			services.ServiceProxy proxy = new services.ServiceProxy();
			proxy.setEndpoint("http://localhost:8080/videolibrary/services/Service");
			latestMovieDetailsArray = proxy.latestMovies();
			for(int i = 0 ; i<latestMovieDetailsArray.length; i++)
					System.out.println(latestMovieDetailsArray[i]);
		}catch(Exception e){
			e.printStackTrace();
		}
		return latestMovieDetailsArray;
	}
	public void getSelectedMovieDetails(int movieID){
		System.out.println("qwertyuioasdfghjzxcvbnm");
	}
}
